{include file="public/head"}

<body>
<div id="wrapper">

    <div class="gray-bg dashbard-1">
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-content">
                            <form class="form-horizontal m-t" id="commentForm">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">角色名称：</label>
                                    <div class="col-sm-8">
                                        <input id="name" name="name" maxlength="50" type="text" class="form-control" required="" aria-required="true">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">角色描述：</label>
                                    <div class="col-sm-8">
                                        <input id="remark" name="remark" maxlength="50" type="text" class="form-control" required="" aria-required="true">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">权限选择：</label>
                                    <div class="col-sm-9">
                                        {volist name="ParentList" id="v"}
                                        <div class="row" style="border-bottom: 1px solid #eaeaea;padding: 15px 15px;width: 472px;">
                                            <div class="checkbox">
                                                <label>
                                                    <input type="checkbox" class="firchecked" value="{$v.id}" name="user-Character-0">{$v.name}
                                                </label>
                                            </div>
                                            <div class="col-sm-10">
                                                {volist name="$v.SonList" id="vv"}
<!--                                                    <label class="checkbox-inline">-->
                                                        <input type="checkbox" value="{$vv.id}" class="secchecked" id="inlineCheckbox1" name="user-Character-0">{$vv.name}
<!--                                                    </label>-->
                                                {/volist}
                                            </div>
                                        </div>
                                        {/volist}
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-4 col-sm-offset-3">
                                        <button class="btn btn-primary" type="submit">确认添加</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer"}
<script>
    $(".secchecked").on('click', function () {
        if($(this).parent().find('input:checked').length > 0) {
            $(this).closest(".row").find('.firchecked').prop('checked',true)
        }else {
            $(this).closest(".row").find('.firchecked').prop('checked',false)
        }

    })
    $('form').submit(function (e) {
        e.preventDefault();

        var str="";
        $("[name=user-Character-0]:checkbox:checked").each(function(){
            str+=$(this).val()+",";
        });
        str = str.substr(0,str.length-1);

        $.ajax({
            type:"post",
            url:"{:url('Role/RoleAdd')}",
            data:{
                name:$('#name').val(),
                remark:$('#remark').val(),
                power: str,
            },
            dataType:"json",
            success:function(data){
                if(data.status == 1){
                    layer.msg(data.message,{icon: 6,time:1500},function () {
                        window.top.location.reload();
                    });
                }else{
                    layer.msg(data.message,{icon: 5,time:1500});
                }
            }
        })
    })
</script>
</body>

</html>
